package org.mosquitos.chat;

import java.io.IOException;

import net.jxta.peergroup.PeerGroup;
import net.jxta.pipe.InputPipe;
import net.jxta.pipe.PipeService;

public class PipeReceiveService implements Runnable {
	private PeerGroup peerGroup;
	private String name;
	
	public PipeReceiveService(PeerGroup peerGroup,String name){
		this.peerGroup = peerGroup;
		this.name = name;
	}

	public void run() {
		
		//while(true){
			PipeService pipeService = peerGroup.getPipeService();
			InputPipe inputPipe = null;
			try {
				inputPipe = pipeService.createInputPipe(AdvertisementCreator.createAdv(peerGroup, name, PipeService.UnicastType, "urn:jxta:uuid-59616261646162614E504720503250333CF917BFDA5E464FA4DFBF84736ED2F904"),new PipeReciveListener());
				System.out.println("create inputPipe:"+inputPipe.getPipeID().toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
			//inputPipe.close();
			/*
	        synchronized (this){
		        try {
					this.wait(1*2*1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
	        }
	        */
		//}
	}

}
